<template>
	<view class="orderList">
		<headertop title="我的设备" str="orderlist" str1="oridei" :back1="back1"></headertop>
		<view class="orderListback"></view>
		<view class="" :style="{'margin-top':statusBarHeight+'px','width':'100%','height':barHeight+'px'}">
		</view>
		<view class="seachbox">
			<image :src="_static('/images/Frame@2x(20).png')" class="lefticon" mode="">
			</image>
			<input type="text" v-model="query.keywords" placeholder="请输入关键词进行搜索" />
			<view class="seachboxbtn" @click="init('搜索')">
				搜索
			</view>
			<image :src="_static('/images/removeicon.png')" class="closeicon" @click="closeinput" v-if="query.keywords"
				mode="">
			</image>
		</view>
		<scroll-view :scroll-left="leftnumstr" scroll-x="true" class="classifybox">
			<view style="display: inline-block;margin-right: 50rpx;">
				<view :class="query.type=='all'?'itembox activecolor':'itembox'" @click="qiehuan('all')">
					<span>全部</span>
					<view class="activebox" v-if="query.type=='all'">

					</view>
				</view>
			</view>
			<view style="display: inline-block;margin-right: 50rpx;">
				<view :class="query.type=='unpaid'?'itembox activecolor':'itembox'" @click="qiehuan('unpaid')">
					<span>待付款</span>
					<view class="activebox" v-if="query.type=='unpaid'">

					</view>
				</view>
			</view>
			<view style="display: inline-block;margin-right: 50rpx;">
				<view :class="query.type=='nosend'?'itembox activecolor':'itembox'" @click="qiehuan('nosend')">
					<span>待发货</span>
					<view class="activebox" v-if="query.type=='nosend'">

					</view>
				</view>
			</view>
			<view style="display: inline-block;margin-right: 50rpx;">
				<view :class="query.type=='nohexiao'?'itembox activecolor':'itembox'" @click="qiehuan('nohexiao')">
					<span>待核销</span>
					<view class="activebox" v-if="query.type=='nohexiao'">

					</view>
				</view>
			</view>
			<view style="display: inline-block;margin-right: 50rpx;">
				<view :class="query.type=='noget'?'itembox activecolor':'itembox'" @click="qiehuan('noget')">
					<span>待收货</span>
					<view class="activebox" v-if="query.type=='noget'">

					</view>
				</view>
			</view>
			<view style="display: inline-block;margin-right: 50rpx;">
				<view :class="query.type=='wancheng'?'itembox activecolor':'itembox'" @click="qiehuan('wancheng')">
					<span>已完成</span>
					<view class="activebox" v-if="query.type=='wancheng'">

					</view>
				</view>
			</view>
		</scroll-view>
		<view class="itemboxss">
			<view class="msgicon" v-if="!list.length">
				<image :src="_static('/images/wxnone.png')" mode="widthFix">
				</image>
				<view class="msgtext">
					暂无订单
				</view>
			</view>
			<view class="itembox" v-for="(item,index) in  list" :key="index" @click="gopage('订单详情',item.id)">
				<view class="itembox_center">
					<view class="topline">
						<view class="dingdanbinhao">
							<image :src="_static('/images/Frame@2x(21).png')" class="dingdanbinhao_icon" mode="">
							</image>
							<span>订单编号：{{item.order_sn}}</span>
						</view>
						<view class="statustext">
							{{item.status_text}}
						</view>
					</view>
					<view class="spinfo" v-for="ite in  item.items" :key="ite.id" v-if="item.items">
						<image :src="_static(ite.goods_image)" mode=""></image>
						<view class="text1">
							<view class="l1">
								<view class="bt1">{{ite.goods_title}}</view>
							</view>
							<view class="l2">
								{{ite.goods_sku_text}}
							</view>
							<view class="yajinbox">
								<span>x{{ite.goods_num}}</span>
								<view class="tihuofs">
									￥{{ite.goods_price}}
								</view>
							</view>
						</view>
					</view>
					<view class="bottomline">
						<view class="" style="display: flex;">
							<view class="borderbtn" @click.stop="qxdd(item)">
								取消订单
							</view>
							<view class="btn" style="margin-left: 28rpx;" @click.stop="ljzf(item)">
								立即支付
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<up-popup :show="show" mode="center">
			<view class="shangchuandanhaobox">
				<view class="titke">
					上传物流单号
				</view>
				<view class="inputbox">
					<view class="linebox">
						<view class="titlelabel">
							物流公司：
						</view>
						<input type="text" placeholder="请输入公司" />
					</view>
					<view class="linebox" style="margin-top: 20rpx;">
						<view class="titlelabel">
							物流单号：
						</view>
						<input type="text" placeholder="请输入单号" />
					</view>
				</view>
				<view class="btnss">
					<view class="btn1">
						取消
					</view>
					<view class="btn2">
						确定
					</view>
				</view>
			</view>
		</up-popup>
	</view>
</template>

<script setup>
	import ulm, {
		$api
	} from '@/ulm';
	import {
		onPageScroll,
		onLoad,
		onShow,
		onReachBottom
	} from "@dcloudio/uni-app";
	import {
		ref,
		reactive,
		onMounted
	} from 'vue'
	import {
		_static
	} from '@/ulm/utils/url.js'
	import headertop from '@/components/header.vue'
	const statusBarHeight = ref('')
	const show = ref(false)
	const leftnumstr = ref('')
	const barHeight = ref('')
	const list = ref([])
	const back1 = ref('')
	const lastpage = ref(0)
	const query = reactive({
		page: 1,
		limit: 10,
		keywords: '',
		type: 'all'
	})
	onShow(() => {
		query.page = 1
		list.value = []
		init()
	})
	onReachBottom(() => {
		if (lastpage.value > query.page) {
			query.page++
			init()
		}
	})

	onPageScroll((e) => {

		if (e.scrollTop > 100) {
			back1.value = '#81D6FF'
		} else {
			back1.value = ''
		}

	})
	onMounted(() => {
		statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight
		const {
			top,
			height
		} = wx.getMenuButtonBoundingClientRect();
		barHeight.value = height ? height + (top - statusBarHeight.value) * 2 : 38;
	})

	async function init() {
		const res = await $api.orderlist1(query)
		if (res.code == 1) {
			list.value.push(...res.data.data)
			lastpage.value = res.data.last_page
		}
	}

	function qiehuan(str) {
		if (str != 'all') {
			query.keywords = ''
		}
		query.type = str
		query.page = 1
		list.value = []
		init()
	}

	function closeinput() {
		query.keywords = ''
		query.type = 'all'
		query.page = 1
		list.value = []
		init()
	}
</script>

<style lang="scss">
	.msgicon {
		width: 608rpx;
		margin: 100rpx auto;
		overflow: hidden;

		.msgtext {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #86909C;
			text-align: center;
			width: 100%;
			margin-top: 30rpx;
		}

		image {
			width: 608rpx;
		}
	}

	.activecolor {
		color: #2AB4F5 !important;
	}


	::v-deep .u-popup__content {
		background-color: rgba(255, 0, 0, 0) !important;
	}

	.shangchuandanhaobox {
		width: 600rpx;
		height: 476rpx;
		background: linear-gradient(180deg, #CAEEFF 0%, #FFFFFF 23%);
		border-radius: 32rpx 32rpx 32rpx 32rpx;
		overflow: hidden;

		.titke {
			width: 100%;
			text-align: center;
			margin-top: 48rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 36rpx;
			color: #1D2129;
		}

		.btnss {
			width: 520rpx;
			margin: auto;
			margin-top: 42rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.btn1 {
				width: 244rpx;
				height: 74rpx;
				background: #F2F3F5;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				text-align: center;
				line-height: 74rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #4E5969;
			}

			.btn2 {
				width: 244rpx;
				height: 74rpx;
				background: #2AB4F5;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				text-align: center;
				line-height: 74rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 28rpx;
				color: #FFFFFF;
			}
		}

		.inputbox {
			width: 536rpx;
			margin: auto;
			margin-top: 44rpx;
			overflow: hidden;

			.linebox {
				width: 100%;
				height: 84rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				background: #F7F8FA;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				border: 2rpx solid #F7F8FA;

				.titlelabel {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #1D2129;
					margin-left: 30rpx;
				}

				input {
					text-align: right;
					font-size: 28rpx;
					margin-right: 30rpx;
				}
			}
		}
	}

	.itemboxss {
		width: 686rpx;
		margin: auto;
		margin-top: 30rpx;



		.itembox {
			width: 686rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(0, 0, 0, 0.18);
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin-bottom: 28rpx;
			overflow: hidden;

			&_center {
				width: 630rpx;
				margin: auto;
				overflow: hidden;

				.bottomline {
					width: 100%;
					overflow: hidden;
					height: 124rpx;
					border-top: 1rpx solid #C9CDD4;
					display: flex;
					align-items: center;
					margin-top: 28rpx;
					flex-direction: row-reverse;

					.borderbtn {
						width: 190rpx;
						height: 64rpx;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
						border: 2rpx solid #C9CDD4;
						text-align: center;
						line-height: 64rpx;
						font-weight: 400;
						font-size: 28rpx;
						color: #4E5969;
					}

					.btn {
						width: 178rpx;
						height: 64rpx;
						background: #EEF9FF;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
						text-align: center;
						line-height: 64rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: bold;
						font-size: 28rpx;
						color: #2AB4F5;
					}
				}

				.spinfo {
					width: 100%;
					overflow: hidden;
					margin-top: 36rpx;
					display: flex;
					align-items: center;

					image {
						width: 156rpx;
						height: 156rpx;
						border-radius: 16rpx 16rpx 16rpx 16rpx;
					}

					.text1 {
						width: 452rpx;
						margin-left: 16rpx;
						overflow: hidden;

						.l1 {
							display: flex;
							align-items: center;
							width: 100%;

							.bt1 {
								width: 80%;
								display: -webkit-box;
								-webkit-box-orient: vertical;
								-webkit-line-clamp: 1;
								overflow: hidden;
								font-family: PingFang SC, PingFang SC;
								font-weight: 500;
								font-size: 28rpx;
								color: #1D2129;
							}

							.bs {
								width: 64rpx;
								height: 40rpx;
								background: #FFEFDE;
								border-radius: 4rpx 4rpx 4rpx 4rpx;
								text-align: center;
								line-height: 40rpx;
								font-family: PingFang SC, PingFang SC;
								font-weight: 400;
								font-size: 24rpx;
								color: #A46F3A;
							}

							.box {
								width: 48rpx;
								height: 32rpx;
								background: #7EBC79;
								border-radius: 4rpx 16rpx 4rpx 16rpx;
								font-family: PingFang SC, PingFang SC;
								font-weight: 500;
								font-size: 24rpx;
								color: #FFFFFF;
								text-align: center;
								line-height: 32rpx;
								margin-right: 8rpx;
							}
						}

						.l2 {
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 24rpx;
							color: #7F7F7F;
							overflow: hidden;
							word-break: break-all;
							white-space: nowrap;
							margin-top: 18rpx;
							width: 408rpx;
						}

						.yajinbox {
							display: flex;
							align-items: center;
							margin-top: 28rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 24rpx;
							color: #7F7F7F;
							justify-content: space-between;

							.tihuofs {
								font-family: PingFang SC, PingFang SC;
								font-weight: 400;
								font-size: 28rpx;
								color: #F53F3F;
							}
						}
					}
				}

				.topline {
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-top: 28rpx;



					.dingdanbinhao {
						width: 75%;
						word-break: break-all;
						/* 或 */
						display: flex;
						align-items: center;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 26rpx;
						color: #4E5969;

						&_icon {
							width: 32rpx;
							height: 32rpx;
						}
					}

					.statustext {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 32rpx;
						color: #FF7613;
					}
				}
			}
		}
	}

	.orderList {
		width: 100%;
		overflow: hidden;
		position: relative;

		.orderListback {
			width: 100%;
			height: 664rpx;
			background: linear-gradient(180deg, #CAEEFF 16%, rgba(240, 250, 255, 0) 100%);
			position: absolute;
			z-index: -1;
		}

		.seachbox {
			width: 686rpx;
			height: 68rpx;
			background: rgba(255, 255, 255, 0.65);
			border-radius: 34rpx 34rpx 34rpx 34rpx;
			margin: auto;
			overflow: hidden;
			margin-top: 6rpx;
			display: flex;
			align-items: center;
			position: relative;

			.lefticon {
				margin-left: 20rpx;
				width: 32rpx;
				height: 32rpx;
			}

			input {
				margin-left: 16rpx;
				font-size: 24rpx;
			}

			.seachboxbtn {
				width: 112rpx;
				height: 44rpx;
				line-height: 44rpx;
				text-align: center;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				position: absolute;
				color: #1D2129;
				border-left: 2rpx solid #86909C;
				right: 0%;
			}
		}

		.classifybox {
			width: 100%;
			margin: auto;
			margin-left: 32rpx;
			white-space: nowrap;
			margin-top: 40rpx;

			.itembox {
				width: 96rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 32rpx;
				color: #1D2129;
				position: relative;
				margin-bottom: 28rpx;
				display: flex;
				flex-direction: column;
				align-items: center;

				.activebox {
					width: 48rpx;
					height: 6rpx;
					background: #2AB4F5;
					border-radius: 4rpx 4rpx 4rpx 4rpx;
					position: absolute;
					bottom: -70%;
					margin-top: 10rpx;
				}
			}
		}

	}
</style>